package com.jiesen.base.utils;

import org.springframework.security.crypto.bcrypt.BCrypt;

public class PasswordUtils {

    /**
     * 密码验证
     * @param password      输入的密码
     * @param dataPassword   数据库密码
     * @return  是否正确
     */
    public static boolean passwordCompare(String password,String dataPassword){
        return BCrypt.checkpw(password, dataPassword);
    }

    /**
     * 密码加密
     * @param password  要加密的密码
     * @return  加密后的密码
     */
    public static String getPasswordSecurity(String password){
        String salt = BCrypt.gensalt();
        String hashpw = BCrypt.hashpw(password, salt);
        return hashpw;
    }

    public static void main(String[] args) {
        String passwordSecurity = getPasswordSecurity("admin");
        System.out.println(passwordSecurity);
    }

}
